# 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
#
#
#
#  示例：
#
#  输入：1->2->4, 1->3->4
# 输出：1->1->2->3->4->4
#
#  Related Topics 链表
#  👍 1199 👎 0


# leetcode submit region begin(Prohibit modification and deletion)
# Definition for singly-linked list.
from myself.listnode import ListNode


class Solution(object):
    def mergeTwoLists(self, l1, l2):
        p1 = l1

        p2 = l2

        r = t = ListNode(None)
        while p1 and p2:

            if p1.val > p2.val:
                t.next, p2 = p2, p2.next
            else:
                t.next, p1 = p1, p1.next

        t.next = p1 if p1 else p2
        return r


# leetcode submit region end(Prohibit modification and deletion)

if __name__ == '__main__':
    Solution().mergeTwoLists('PyCharm')
